package com.zyl.edthresholdtraining.controller;

import com.zyl.edthresholdtraining.common.AppConstant;
import com.zyl.edthresholdtraining.service.ExcelService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletResponse;

/**
 * @author jiangtingfeng
 * @description 导出被试测试结果数据
 * @date 2020/8/1/001
 */
@Controller
@RequestMapping(AppConstant.PROJECT_NAME+"/excel")
public class ExcelController {

    @Autowired
    private ExcelService excelService;

    @GetMapping("/download/{userName}")
    @ApiOperation("跳转到登入页面")
    public String excel(@PathVariable("userName") String userName){
        if ("zyl".equals(userName) || "lry".equals(userName)) {
            return "excel";
        } else {
            return "error";
        }
    }

    @GetMapping("/get")
    @ApiOperation("跳转到excel页面")
    public String get(@RequestParam("type") String type, HttpServletResponse response, Model model) throws Exception{
        //可以添加获取列表数据的条件
        boolean b = excelService.downloadResource(type, response);
        if (!b) {
            model.addAttribute("msg","无数据进行导出！");
        }
        return "excel";
    }





}
